package com.cdream.basic.algorithm.leetcode.findElement;

/**
 * @author cdream
 * @date 2022/2/14
 */
public class Question540 {
    public int singleNonDuplicate(int[] nums) {
        int start = 0;
        int end = nums.length-1;
        while(start<=end){
            if(start==end){
                return nums[start];
            }
            int mid = start + (end - start) / 2;

            if(mid%2==0){
                // mid = 4
                if (nums[mid]==nums[mid+1]){
                    start = mid+2;
                }else if(nums[mid]==nums[mid-1]){
                    end = mid-2;
                }

            }else {
                // mid = 5
                if (nums[mid]==nums[mid+1]){
                    end = mid-1;
                }else if(nums[mid]==nums[mid-1]){
                    start = mid+1;
                }

            }
        }
        return -1;
    }

    public static void main(String[] args) {
        // new Question540().singleNonDuplicate(new int[]{1,1,2,3,3});
        System.out.println(Integer.toBinaryString(0xEF));
        System.out.println(Integer.toBinaryString(0xEF ^ 1) );
    }
}
